namespace ContactSMS.Client.Views;

using ContactSMS.Client.ViewModels;

[QueryProperty("MessageId", "Id")]
public partial class MessageDetailPage : ContentPage
{
    private readonly MessageDetailViewModel messageDetailViewModel;

    public MessageDetailPage(MessageDetailViewModel messageDetailViewModel)
    {
        InitializeComponent();
        NavigationPage.SetHasNavigationBar(this, false);
        this.messageDetailViewModel = messageDetailViewModel;
        this.BindingContext = messageDetailViewModel;
    }

    public String MessageId
    {
        set
        {
            if (!string.IsNullOrEmpty(value) && long.TryParse(value, out long messageId))
            {
                LoadMessage(messageId);
            }
        }
    }

    private async void LoadMessage(long messageId)
    {
        await messageDetailViewModel.LoadMessage(messageId);
    }
}